<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="${ctxPath!}/layui/css/layui.css" rel="stylesheet" type="text/css">
    <% include("/templates/common/dialog.html"){} %>
</head>
<div style="padding:10px 50px 10px 10px">
    <form id="orgForm" method="post" action="${ctxPath!}/sys/org/edit" class="layui-form">
        <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc; padding-bottom: 5px;">机构信息</div>
        <input type="hidden" name="id" value="${org.id}"/>
        <input type="hidden" name="image" value="${org.image}" id="image"/>
        <div class="layui-form-item">
            <label class="layui-form-label">机构名称</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="name" value="${org.name!}" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">机构地址</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="address" value="${org.address!}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">机构联系人</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="manager" value="${org.manager!}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="telephone" value="${org.telephone!}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="remark" value="${org.remark!}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">机构图片</label>
            <div class="layui-input-block">
                <img id="image1" src="${org.image!}" alt="" style="width: 50px;height: 50px;">
                <button type="button" class="layui-btn" id="uploadButton">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="submitButton" class="layui-btn" lay-submit lay-filter="*">保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeAll()">取消</button>
            </div>
        </div>
    </form>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js?v=1.0.1"></script>
<script type="text/javascript">
    layui.use(['form','upload'], function(){
        var form = layui.form;
        var upload = layui.upload;
        form.on('submit(*)', function(data){
            $('#submitButton').attr("disabled",true);
            $.post($("#orgForm").attr("action"), $("#orgForm").serialize(), function(data){
                if(data.status == 200){
                    layer.alert(data.msg, {
                        icon: 1,
                        skin: 'layer-ext-moon'
                    },function () {
                        parent.myJqGrid.reloadGrid({});
                        parent.layer.closeAll();
                    });
                }else{
                    layer.alert(data.msg, {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                }
            });
            return false; //阻止表单跳转。
        });

        //上传缩略图
        upload.render({
            elem: '#uploadButton',
            url: '/uploadOrgImage',
            method : "POST",
            auto: true, //选择文件后不自动上传
            data: {orgId:'${org.id!}'},
            done: function(res, index, upload){
                $('#image').val(res.src);
                $("#image1").attr("src",res.src);
            },
            choose: function(obj) {
                //将每次选择的文件追加到文件队列
                var files = obj.pushFile();

                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                obj.preview(function (index, file, result) {
                    $('#image').attr('src',result);
                    //obj.upload(index, file); //对上传失败的单个文件重新上传，一般在某个事件中使用
                    //delete files[index]; //删除列表中对应的文件，一般在某个事件中使用
                })
            }
        });

    });
    function closeAll() {
        parent.layer.closeAll();
    }
</script>